package com.zlsy.springbootdemo.rabbitmq.controller;

import com.zlsy.springbootdemo.rabbitmq.stream.Source;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhouliang
 * @date 2021/1/8 16:17
 */
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrdinaryController {

  private final Source source;

  @GetMapping(value = "/test")
  public boolean send(String msg) {
    MessageChannel messageChannel = source.ordinaryOut();
    Message<String> message = MessageBuilder.withPayload(msg).build();
    boolean send = messageChannel.send(message);
    log.info("{}", send);
    return send;
  }
}
